package com.kedll.library.addimg;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.ViewGroup.LayoutParams;
import android.widget.FrameLayout;
import android.widget.ImageView;
import android.widget.RelativeLayout;

import com.kedll.library.R;
import com.kedll.library.util.ImageLoadUtil;

import java.util.Map;


public class AddImgAdapter02 extends AddImgAdapter01 {


    public AddImgAdapter02(Context context, int width) {
        super(context, width);
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        // TODO Auto-generated method stub
        Holder holder = null;
        if (convertView == null) {
            holder = new Holder();
            convertView = LayoutInflater.from(getContext()).inflate(R.layout.item_add_img02, null);
            holder.fl_img = convertView.findViewById(R.id.fl_img);
            holder.rl_selected = convertView
                    .findViewById(R.id.rl_selected);
            holder.iv_img = convertView.findViewById(R.id.iv_img);
            convertView.setTag(holder);
        } else {
            holder = (Holder) convertView.getTag();
        }
        LayoutParams lp = holder.fl_img.getLayoutParams();
        lp.width = width;
        lp.height = width;
        holder.fl_img.setLayoutParams(lp);
        LayoutParams lp1 = holder.iv_img.getLayoutParams();
        lp1.width = width;
        lp1.height = width;
        Map<String, Object> item = getItem(position);

        if (parse.parseBool(item.get("isCheck"))) {
            holder.rl_selected.setVisibility(View.VISIBLE);
        } else {
            holder.rl_selected.setVisibility(View.GONE);
        }

        String url = "file://" + parse.isNull(item.get("imagePath"));
        ImageLoadUtil.getInstance().ImageLoad(getContext(), url, holder.iv_img);

        holder.iv_img.setOnClickListener(new MyOnClickListener(holder.iv_img, item, position));
        holder.rl_selected.setOnClickListener(new MyOnClickListener(holder.rl_selected, item, position));
        return convertView;
    }

    static class Holder {
        FrameLayout fl_img;// 父布局
        RelativeLayout rl_selected;// 已选中布局
        ImageView iv_img;// 本地图片
    }
}
